package com.android.boncen.commonFrame.tools;

import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

/**
 * Created by Boncen on 2017/1/24.
 */

public class DesityUtil{
    public static int dip2px(Context context, float dpValue){
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int)(dpValue*scale + 0.5f);
    }

    public static int px2dip(Context context,float pxValue){
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int)(pxValue*scale + 0.5f);
    }
    private static String macAddress ="";
    public static String getMacAddress(Context context) {

        if (!TextUtils.isEmpty(macAddress))
        {
            return macAddress;
        }
        String mac = "";
        String androidId = "";
        String deviceId = "";
        try {
            // 获取wifi管理器
            WifiManager wifiMng = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            WifiInfo wifiInfor = wifiMng.getConnectionInfo();
            mac = wifiInfor.getMacAddress();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            deviceId = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
        } catch (Exception e) {
            e.printStackTrace();
        }
        String macSt = mac + androidId + deviceId;
        macSt = macSt.trim();
        macAddress = macSt.replace(":", "");
        return macAddress;
    }
}